﻿@using  Telerik.Web.Mvc.UI;
@using Helena.Areas.Ventas.Models;
@model  Helena.Areas.Reportes.Models.CierreCaja
            
@{
    ViewBag.Title = "Cierre de Caja Diario";
    Layout = "~/Views/Shared/_Layout.cshtml";
    //List<DetalleVentaView> DtVnt = (List<DetalleVentaView>)Session["DetalleVenta"];
}

<script type="text/javascript">
    function ventas_onRowDataBound(e) {
        var grid = $(this).data('tGrid');
        expandFirstRow(grid, e.row);
    }

    function expandFirstRow(grid, row) {
        if (grid.$rows().index(row) == 0) {
            grid.expandRow(row);
        }
    }

    function onChange(e) {

        var FisicoSoles = parseFloat($("#FisicoSoles").val())
        var TotalSoles = parseFloat($("#TotalVentaNeta").val())
        $("#Resultado").val(Math.round((FisicoSoles - TotalSoles) * 100) / 100)
    }
</script>


@Html.Telerik().ScriptRegistrar().Globalization(true)

@using (Html.BeginForm())
{
    <fieldset>
        <legend>Cierre de Caja</legend>
            <table style="width:100%">
                <tr>
                    <td>
                        <div class="editor-label"><b>Seleccione un dia para el cierre de caja</b></div>
                        <div class="editor-field">@Html.Telerik().DatePickerFor(m => m.fecha).Value(DateTime.Now)</div>
                        <div class="editor-label"><b>Ingrese la Cantidad de Soles Fisicos</b></div>
                        <div class="editor-field">@Html.Telerik().CurrencyTextBoxFor(m => m.DisponibleCaja).InputHtmlAttributes(new { style = "font-size:30px" })</div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <p><input type="submit" value="Consultar" /></p>
                    </td>
                </tr>
            </table>
    </fieldset>
}
@if (Model != null)
{
    using (Html.BeginForm())
    {
        <fieldset>
            <legend>Datos del sistema</legend>
                <table style="width:100%">
                    <tr>
                        <td>@Html.LabelFor(m => m.Vendedor)<br />
                            @Html.Telerik().AutoCompleteFor(m => m.Vendedor)@Html.ValidationMessageFor(m => m.Vendedor)</td>
                        <td>@Html.LabelFor(m => m.fecha)<br />
                            @Html.Telerik().AutoCompleteFor(m => m.fecha)@Html.ValidationMessageFor(m => m.fecha)</td>
                        <td>
                            <table>
                                <tr>
                                    <th>@Html.LabelFor(m => m.DisponibleCaja)</th>
                                    <td>@Html.Telerik().CurrencyTextBoxFor(m => m.DisponibleCaja).Name("FisicoSoles").ClientEvents(events => events.OnChange("onChange")).InputHtmlAttributes(new { style = "font-size:20px" })</td>
                                    <td>@Html.TextBox("Resultado")</td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                    </table>

                    <table style="width:100%">
                    <tr>
                        <td>
                            <table style="width:100%">
                                <tr>
                                    <td>
                                        <table style="width:100%">
                                            <tr>
                                                <td>
                                                    <div class="editor-label">@Html.LabelFor(m => m.TotalVentaBruta)</div>
                                                    <div class="editor-field">@Html.Telerik().CurrencyTextBoxFor(m => m.TotalVentaBruta).CurrencySymbol("S/").InputHtmlAttributes(new { style = "font-size:20px" })</div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <div class="editor-label">@Html.LabelFor(m => m.TotalDescuento)</div>
                                                    <div class="editor-field">@Html.Telerik().CurrencyTextBoxFor(m => m.TotalDescuento).CurrencySymbol("S/").InputHtmlAttributes(new { style = "font-size:20px" })</div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <div class="editor-label">@Html.LabelFor(m => m.TotalVentaNeta)</div>
                                                    <div class="editor-field">@Html.Telerik().CurrencyTextBoxFor(m => m.TotalVentaNeta).CurrencySymbol("S/").InputHtmlAttributes(new { style = "font-size:20px" })</div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <div class="editor-label">@Html.LabelFor(m => m.TotalEfectivo)</div>
                                                    <div class="editor-field">@Html.Telerik().CurrencyTextBoxFor(m => m.TotalEfectivo).CurrencySymbol("S/").InputHtmlAttributes(new { style = "font-size:20px" })</div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <div class="editor-label">@Html.LabelFor(m => m.Pagos_de_Venta_en_Dolares)</div>
                                                    <div class="editor-field">@Html.Telerik().CurrencyTextBoxFor(m => m.Pagos_de_Venta_en_Dolares).CurrencySymbol("US$").InputHtmlAttributes(new { style = "font-size:20px" })</div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <div class="editor-label">@Html.LabelFor(m => m.Pagos_de_venta_TarjetaSoles)</div>
                                                    <div class="editor-field">@Html.Telerik().CurrencyTextBoxFor(m => m.Pagos_de_venta_TarjetaSoles).CurrencySymbol("S/").InputHtmlAttributes(new { style = "font-size:20px" })</div>
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                    <td>
                                        @(Html.Telerik().Grid<Venta>()
                                            .Name("Ventas")
                                            .Columns(columns =>
                                                {
                                                    columns.Bound(o => o.ID).Width(50);
                                                    columns.Bound(o => o.Ticket).Width(100);
                                                    columns.Bound(o => o.Boleta).Width(100);
                                                    columns.Bound(o => o.Factura).Width(100);
                                                    columns.Bound(o => o.Sub_Total).Width(100);
                                                    columns.Bound(o => o.Total_En_Soles).Width(100);
                                                    columns.Bound(o => o.Estado).ClientTemplate("<input type='checkbox' disabled='disabled' name='Estado' <#= Estado? checked='checked' : '' #> />"); 
                                                }
                                            )
                                            
                                                .ClientEvents(events => events.OnRowDataBound("ventas_onRowDataBound"))
                                                .DetailView(details => details.ClientTemplate(
                                                        Html.Telerik().Grid<DetalleVentaView>()
                                                            .Name("Venta_<#= ID #>")
                                                            .Columns(columns =>
                                                            {
                                                                columns.Bound(o => o.NombreProducto).Width(101);
                                                                columns.Bound(o => o.PrecioU).Width(140);
                                                                columns.Bound(o => o.Cantidad ).Width(200);
                                                                columns.Bound(o => o.Subtotal).Width(200);
                                                            })
                                                            .DataBinding(dataBinding => dataBinding.Ajax()
                                                            .Select("_DetalleVenta", "CierreCaja", new { VentaID = "<#= ID #>" }))
                                                            .Pageable()
                                                            .Sortable()
                                                            .Filterable()
                                                            .ToHtmlString()
                                                ))
                      
                                            .DataBinding(databinding =>
                                            {
                                                databinding.Ajax().Select("Ventas", "CierreCaja");
                                            })
                                            .Scrollable(scrolling => scrolling.Enabled(true))
                                            .Sortable(sortable => sortable.Enabled(true))
                                            .Pageable(paging=>paging.Enabled(true))
                                            .Filterable(filtering =>filtering.Enabled(true))
                                            .Groupable(grouping=>grouping.Enabled(true))
                                            .Footer(true)
                                        )
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
        </fieldset>
        <fieldset>
            <legend>Detalles</legend>
                <table style="width:80%">
                    <tr>
                        <td>
                            <table style="width:80%">
                                <tr>
                                    <td></td>
                                    <th>@Html.LabelFor(m => m.NTicket)</th>
                                    <th>@Html.LabelFor(m => m.InicioTicket)</th>
                                    <th>@Html.LabelFor(m => m.FinTicket)</th>
                                    <th>@Html.LabelFor(m => m.TotalTicketSoles)</th>
                                    <th>@Html.LabelFor(m => m.TotalTicketDolares)</th>
                                    <th>@Html.LabelFor(m => m.NTicketAnulados)</th>
                                </tr>
                                <tr>
                                    <td><b>Ticket - Factura</b></td>
                                    <td>@Html.Telerik().AutoCompleteFor(m => m.NTicket).HtmlAttributes(new { style = "width: 150px;font-size:20px" })</td>
                                    <td>@Html.Telerik().AutoCompleteFor(m => m.InicioTicket).HtmlAttributes(new { style = "width: 150px;font-size:20px" })</td>
                                    <td>@Html.Telerik().AutoCompleteFor(m => m.FinTicket).HtmlAttributes(new { style = "width: 150px;font-size:20px" })</td>
                                    <td>@Html.Telerik().CurrencyTextBoxFor(m => m.TotalTicketSoles).CurrencySymbol("S/").InputHtmlAttributes(new { style = "width: 150px;font-size:20px" })</td>
                                    <td>@Html.Telerik().CurrencyTextBoxFor(m => m.TotalTicketDolares).CurrencySymbol("US$").InputHtmlAttributes(new { style = "width: 150px;font-size:20px" })</td>
                                    <td>@Html.Telerik().AutoCompleteFor(m => m.NTicketAnulados).HtmlAttributes(new { style = "width: 150px;font-size:20px" })</td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <table style="width:80%">
                                <tr>
                                    <th></th>
                                    <th>@Html.LabelFor(m => m.NBoleta)</th>
                                    <th>@Html.LabelFor(m => m.InicioBoleta)</th>
                                    <th>@Html.LabelFor(m => m.FinBoleta)</th>
                                    <th>@Html.LabelFor(m => m.TotalBoletaSoles)</th>
                                    <th>@Html.LabelFor(m => m.TotalBoletaDolares)</th>
                                    <th>@Html.LabelFor(m => m.NBoletaAnulados)</th>
                                </tr>
                                <tr>
                                    <td><b>Boletas</b></td>
                                    <td>@Html.Telerik().AutoCompleteFor(m => m.NBoleta).HtmlAttributes(new { style = "width: 150px;font-size:20px" })</td>
                                    <td>@Html.Telerik().AutoCompleteFor(m => m.InicioBoleta).HtmlAttributes(new { style = "width: 150px;font-size:20px" })</td>
                                    <td>@Html.Telerik().AutoCompleteFor(m => m.FinBoleta).HtmlAttributes(new { style = "width: 150px;font-size:20px" })</td>
                                    <td>@Html.Telerik().CurrencyTextBoxFor(m => m.TotalBoletaSoles).CurrencySymbol("S/").InputHtmlAttributes(new { style = "width: 150px;font-size:20px" })</td>
                                    <td>@Html.Telerik().CurrencyTextBoxFor(m => m.TotalBoletaDolares).CurrencySymbol("US$").InputHtmlAttributes(new { style = "width: 150px;font-size:20px" })</td>
                                    <td>@Html.Telerik().AutoCompleteFor(m => m.NBoletaAnulados).HtmlAttributes(new { style = "width: 150px;font-size:20px" })</td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <table style="width:80%">
                                <tr>
                                    <th></th>
                                    <th>@Html.LabelFor(m => m.NFactura)</th>
                                    <th>@Html.LabelFor(m => m.InicioFactura)</th>
                                    <th>@Html.LabelFor(m => m.FinFactura)</th>
                                    <th>@Html.LabelFor(m => m.TotalFacturaSoles)</th>
                                    <th>@Html.LabelFor(m => m.TotalFacturaDolares)</th>
                                    <th>@Html.LabelFor(m => m.NFacturaAnulados)</th>
                                </tr>
                                <tr>
                                    <td><b>Facturas</b></td>
                                    <td>@Html.Telerik().AutoCompleteFor(m => m.NFactura).HtmlAttributes(new { style = "width: 150px;font-size:20px" })</td>
                                    <td>@Html.Telerik().AutoCompleteFor(m => m.InicioFactura).HtmlAttributes(new { style = "width: 150px;font-size:20px" })</td>
                                    <td>@Html.Telerik().AutoCompleteFor(m => m.FinFactura).HtmlAttributes(new { style = "width: 150px;font-size:20px" })</td>
                                    <td>@Html.Telerik().CurrencyTextBoxFor(m => m.TotalFacturaSoles).CurrencySymbol("S/").InputHtmlAttributes(new { style = "width: 150px;font-size:20px" })</td>
                                    <td>@Html.Telerik().CurrencyTextBoxFor(m => m.TotalFacturaDolares).CurrencySymbol("US$").InputHtmlAttributes(new { style = "width: 150px;font-size:20px" })</td>
                                    <td>@Html.Telerik().AutoCompleteFor(m => m.NFacturaAnulados).HtmlAttributes(new { style = "width: 150px;font-size:20px" })</td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
        </fieldset>

        <table style="width:20%"> 
        <tr> 
        <td style="background-color: #CCFF99; color: #808080; font-weight: bold; font-size: 20px; border-style: ridge">
        <@Html.ActionLink("Imprimir", "Imprimir", "CierreCaja",null)>
        </td>
        </tr>
        </table>
    }
}







